<template>
  <div>
    <!-- 黑色模糊遮罩 -->
    <transition name="mask">
      <div class="mask" v-if="newTodoIsOpen"></div>
    </transition>
    <!-- 日志窗口 -->
    <transition name="run">
      <div class="run-window" v-if="newTodoIsOpen">
        <div class="top">
          <!-- 标题 -->
          <div class="title">
            <h2>{{ windowMode.title }}</h2>
            <div class="btns">
              <button @click="closeWindow" class="btn cancel">关闭</button>

            </div>
          </div>
          
          <div v-loading="loading">
            <el-input id="textarea_id"
                      type="textarea" :readonly="true"
                      :autosize="{ minRows: 23, maxRows: 23}"
                      v-model="log">
            </el-input>
          </div>

        </div>
        
      </div>
    </transition>
  </div>
</template>

<script>
let config = {
               headers:{"Authorization": localStorage.getItem("token")}
           };
import date from '@/utils/date'
export default {
  name: "EditTodo",
  components: {
  },
  data() {
    return {
      newTodoIsOpen: false,
      loading:true,
      log:''
    };
  },
  methods: {
    //获取日志
    getTransferLog(){
      // const textarea = document.getElementById('textarea_id');
      this.$axios
      .get('/file/getTransferlog',config)
      .then(res=>{
        // console.log(res.data.data[0])
        this.log = ''
        this.loading = false
        res.data.data.reverse().forEach(item => {
          // console.log(item)
          let logInfo = date.format(new Date(item.dateTime)) + "\r\n" +
              "fileName:[" + item.initialFile + "]," +
              "message:" + item.message + "," +
              "transferState:[" + item.transferState + "]," +
              "executeTime:[" + item.executeTime + "ms],";
          this.log = this.log.concat(logInfo).concat("\r\n\r\n")
        });

      })
    },
    // 打开窗口
    openWindow(type, action, oldValue) {
      this.getTransferLog()
      this.newTodoIsOpen = true;
      this.windowMode = {
        title: type == "todo" ? "运行日志" : "",
        iconClass: type == "todo" ? "icon-clock" : "icon-repeat",
        settingType: type,
      };
      this.settingIsOpen = type == "todo" ? false : true;
      if (action == "edit") {
        this.editMode = true;
        if (type == "todo") {
          this.$store.commit("editItem", {
            type: "todo",
            oldValue,
          });
        } else if (type == "clockIn") {
          this.$store.commit("editItem", {
            type: "clockIn",
            oldValue,
          });
        }
      }
    },
    // 关闭窗口
    closeWindow() {
      this.newTodoIsOpen = false;
      if (this.input.inputContent && !this.editMode) {
        let b = confirm("");
        if (!b) {
          this.$store.commit("clearInput");
        }
      } else {
        this.$store.commit("clearInput");
        this.editMode = false;
      }
    },
    
  },
};
</script>

<style scoped>
/* 遮罩层 */
.mask-enter-active {
  animation: anim 0.4s ease-in-out;
}
.mask-leave-active {
  animation: anim 0.6s ease-in-out reverse;
}
@keyframes anim {
  0% {
    background-color: rgba(0, 0, 0, 0);
    backdrop-filter: blur(0px);
  }
  100% {
    background-color: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(10px);
  }
}
.mask {
  z-index: 99;
  position: absolute;
  display: block;
  top: 0;
  left: 0;
  width: 100%;
  height: 67.5rem;
  background-color: rgba(0, 0, 0, 0.4);
  /* 毛玻璃效果 */
  backdrop-filter: blur(10px);
}

/* 日志窗口 */
.run-enter-active {
  animation: anim1 0.4s ease-in-out;
}
.run-leave-active {
  animation: anim2 0.6s;
}
@keyframes anim1 {
  0% {
    top: calc(50% - 14rem);
    opacity: 0;
  }
  100% {
    top: calc(50% - 12rem);
    opacity: 1;
  }
}
@keyframes anim2 {
  0% {
    top: calc(50% - 12rem);
    opacity: 1;
  }
  100% {
    top: calc(50% - 10rem);
    opacity: 0;
  }
}
.run-window {
  z-index: 100;
  position: absolute;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  left: calc(50% - 26rem);
  top: calc(50% - 12rem);
  width: 52rem;
  min-height: 26rem;
  max-height: 46rem;
  padding: 2rem;
  border-radius: 16px;
  opacity: 1;
  background-color: var(--BG);
  transition: 0.5s ease-in-out;
}
/* 标题和按钮 */
.title {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  height: 2rem;
}

.title > h2 {
  color: var(--Gray-8);
  font-size: 1.5rem;
  line-height: 2rem;
  font-weight: 600;
}
.btn {
  border: 0;
  background: none;
  font-size: 1.25rem;
  line-height: 2rem;
  font-weight: 600;
  cursor: pointer;
}
.cancel {
  color: var(--Gray-6);
}
.cancel:hover {
  color: var(--Gray-7);
}
.cancel:active {
  color: var(--Gray-8);
}
.save {
  margin-left: 2rem;
  color: var(--Theme-6);
}
.save:hover {
  color: var(--Theme-7);
}
.save:active {
  color: var(--Theme-9);
}

.settings {
  display: flex;
  align-items: center;
}
</style>